<?php
/**
 * GET变量XSS过滤
 * 
 * @param $_GET变量键值
 * @param 键不存在或者为空时，返回的默认值
 * @return value
 */
function _g($param, $default = ''){
	return (!isset($_GET[$param]) || empty($_GET[$param])) ? $default : addslashes(htmlspecialchars($_GET[$param], ENT_QUOTES));
}
function _p($param, $default = ''){
	return (!isset($_POST[$param]) || empty($_POST[$param])) ? $default : (htmlspecialchars($_POST[$param], ENT_QUOTES));
}
function dbg($a){
	echo '<pre>';
	print_r($a);exit;
}

function show_error(){
	die('error');
}

function view($a){
	include_once(ROOTDIR . DS . 'hive' . DS . $a . '.tpl');
}
// ------------------------------------------------------------------------

/**
 * Header Redirect
 *
 * Header redirect in two flavors
 * For very fine grained control over headers, you could use the Output
 * Library's set_header() function.
 *
 * @access	public
 * @param	string	the URL
 * @param	string	the method: location or redirect
 * @return	string
 */
if ( ! function_exists('redirect'))
{
	function redirect($uri = '', $method = 'location', $http_response_code = 302)
	{
		if ( ! preg_match('#^https?://#i', $uri))
		{
			$uri = BASEURL . $uri;
		}

		switch($method)
		{
			case 'refresh'	: header("Refresh:0;url=".$uri);
				break;
			default			: header("Location: ".$uri, TRUE, $http_response_code);
				break;
		}
		exit;
	}
}
